package com.lx.entitys;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: chenjiang
 * @Date: 2021/11/18/16:41
 */
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class CovidSumEntity implements WritableComparable<CovidSumEntity> {
    //确诊数
    private Long cases;
    //死亡数
    private Long deaths;

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(cases);
        out.writeLong(deaths);
    }

    /***
     * readFields & write 一定要一一对应
     */
    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.cases = dataInput.readLong();
        this.deaths = dataInput.readLong();
    }

    @Override
    public String toString() {
        return cases + "\t" + deaths;
    }


    @Override
    public int compareTo(CovidSumEntity o) {
        return this.cases - o.getCases() > 0 ? -1 : (this.cases - o.getCases() < 0 ? 1 : 0);
    }
}
